use16
org 0x7c00

%define BOOT_ADDRESS 0x7c00
%define ENTRY_ADDRESS 0x7e00

%define CODE_SEG     0x0008
%define DATA_SEG     0x0010
%define PMAPL4        0xA000

%define PAGE_PRESENT (1 << 0)
%define PAGE_WRITE   (1 << 1)
%define PAGE_SIZE    (1 << 7)



global start:
start:

    ; enable a20 line via BIOS
    ; more compatability by trying different a20 enabling methods
    mov ax, 0x2401
    int 15h

    ;必须跳转下，否则 卡住了
    ;jmp 0:next_0 ; far jump to reload cs

;next_0:
    mov sp,start ;set stack address
    mov bp,sp

    ; init 16bits registers
    xor ax,ax ;zero
    mov ss,ax
    ;mov cs,ax ; cs default 0
    mov ds,ax
    mov es,ax
    mov fs,ax
    mov gs,ax


    mov bx,ENTRY_ADDRESS
    mov cl,2 ; index based 1
    mov al,15    ; num of sectors
    call read_sectors_0



    ;oepn A20
    ; call enable_A20


    ;output hello world
    mov dh,0
    call p

    jmp ENTRY_ADDRESS
    ;jmp switch_to_long_mode_x64


;open A20
;%include "enable_a20.s"
%include "bios_wrapper.s"
;%include 'idt.s'
;%include "gdt.s"
;%include 'long_mode_x64.s'

use16
p:
    mov ax,helloworld
    mov cx,helloworld_len
    ;mov dh,0 ; based 0
    call println
    ret

helloworld:
	db "Hello,World!"
	helloworld_len equ $-helloworld
	;$ -current position
;64 位代码 不能 和前面混合 否则报错
;%include 'into_c_entry.s'

times 510-($-$$) db 0
dw 0xaa55



